package cn.iocoder.yudao.module.pay.job.ftp;

import cn.hutool.extra.ftp.Ftp;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@Data
@Slf4j
public class FtpConfig {
    @Value("${ftp.IP}")
    private String FTP_IP;
    @Value("${ftp.port}")
    private int ftp_port;
    @Value("${ftp.user_name}")
    private String ftp_user_name;
    @Value("${ftp.user_pass}")
    private String ftp_user_pass;

    @Bean
    public Ftp getFtp() {
        //判断目录是否存在，不存在就新建
        log.info("开始初始化ftp");
        try {
            Ftp ftp = new Ftp(FTP_IP, ftp_port, ftp_user_name, ftp_user_pass, StandardCharsets.UTF_8);
            log.info("初始化成功");
            return ftp;
        } catch (Exception e) {

            log.info("初始化FTP失败:{}", e.getMessage());
        }
        return null;

    }
}
